package com.haixiaoke.saas.enterprise.apartment.controller;

import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.common.utils.poi.ExcelUtil;
import com.haixiaoke.saas.house.domain.HouseFacilitiesItem;
import com.haixiaoke.saas.house.service.IHouseFacilitiesItemService;
import com.haixiaoke.saas.system.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 房屋设施价格和状态Controller
 *
 * @author xiaolong
 * @date 2023-10-24
 */
@RestController
@RequestMapping("/enterprise/apartment/item")
public class EnterpriseHouseFacilitiesItemController extends BaseController {
    @Autowired
    private IHouseFacilitiesItemService houseFacilitiesItemService;

    /**
     * 查询房屋设施价格和状态列表
     */
    @PreAuthorize("@ss.hasPermi('business:item:list')")
    @GetMapping("/list")
    public TableDataInfo list(HouseFacilitiesItem houseFacilitiesItem) {
        startPage();
        List<HouseFacilitiesItem> list = houseFacilitiesItemService.selectHouseFacilitiesItemList(houseFacilitiesItem);
        return getDataTable(list);
    }

    /**
     * 导出房屋设施价格和状态列表
     */
    @PreAuthorize("@ss.hasPermi('business:item:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, HouseFacilitiesItem houseFacilitiesItem) {
        List<HouseFacilitiesItem> list = houseFacilitiesItemService.selectHouseFacilitiesItemList(houseFacilitiesItem);
        ExcelUtil<HouseFacilitiesItem> util = new ExcelUtil<HouseFacilitiesItem>(HouseFacilitiesItem.class);
        util.exportExcel(response, list, "房屋设施价格和状态数据");
    }

    /**
     * 获取房屋设施价格和状态详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:item:query')")
    @GetMapping(value = "/{facilitiesItemId}")
    public AjaxResult getInfo(@PathVariable("facilitiesItemId") Long facilitiesItemId) {
        return success(houseFacilitiesItemService.selectHouseFacilitiesItemByFacilitiesItemId(facilitiesItemId));
    }

    /**
     * 新增房屋设施价格和状态
     */
    @PreAuthorize("@ss.hasPermi('business:item:add')")
    @PostMapping
    public AjaxResult add(@RequestBody HouseFacilitiesItem houseFacilitiesItem) {
        return toAjax(houseFacilitiesItemService.insertHouseFacilitiesItem(houseFacilitiesItem));
    }

    /**
     * 修改房屋设施价格和状态
     */
    @PreAuthorize("@ss.hasPermi('business:item:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody HouseFacilitiesItem houseFacilitiesItem) {
        return toAjax(houseFacilitiesItemService.updateHouseFacilitiesItem(houseFacilitiesItem));
    }

    /**
     * 删除房屋设施价格和状态
     */
    @PreAuthorize("@ss.hasPermi('business:item:remove')")
    @DeleteMapping("/{facilitiesItemIds}")
    public AjaxResult remove(@PathVariable Long[] facilitiesItemIds) {
        return toAjax(houseFacilitiesItemService.deleteHouseFacilitiesItemByFacilitiesItemIds(facilitiesItemIds));
    }

    /**
     * 查询房屋设施价格和状态信息
     */
    @GetMapping("/info/{houseId}")
    public AjaxResult info(@PathVariable("houseId") String houseId) {
        HouseFacilitiesItem houseFacilitiesItem = new HouseFacilitiesItem();
        houseFacilitiesItem.setHouseId(houseId);
        return success(houseFacilitiesItemService.selectHouseFacilitiesItemList(houseFacilitiesItem));
    }
}
